package com.tuanzi.webtalk.service.impl;

import com.tuanzi.webtalk.dao.GroupMapper;
import com.tuanzi.webtalk.dao.Group_infoMapper;
import com.tuanzi.webtalk.domain.Group_info;
import com.tuanzi.webtalk.service.GroupService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 雄关漫道真如铁，而今迈过从头越
 **/

@Service
public class GroupServiceImpl implements GroupService {

    @Resource
    private Group_infoMapper group_infoMapper;

    @Resource
    private GroupMapper groupMapper;


    /**
     * 查询素
     * @return
     */
    @Override
    public List<Group_info> getGroups(Integer uid) {
        //首先我们查询这个人属于哪个群组
        List<Integer> integers = groupMapper.selectGroupsByUid(uid);
        //创建这个List集合，用来专门存储群组信息
        List<Group_info> group_infos = new ArrayList<>();
        //接着我们遍历gid，找到所有的群信息
        for (Integer integer : integers) {
            Group_info group_info = group_infoMapper.selectByPrimaryKey(integer);
            group_infos.add(group_info);
        }

        return group_infos;
    }

}
